package com.gmail.blackdog1987.onedollar.dao;

import com.gmail.blackdog1987.onedollar.dao.hibernate.EntityHibernateDao;
import com.gmail.blackdog1987.onedollar.dao.hibernate.jdbc.BaseJdbcDao;
import com.gmail.blackdog1987.onedollar.dao.hibernate.jdbc.JdbcUtil;
import com.gmail.blackdog1987.onedollar.entity.TGoodsCartEntity;
import com.gmail.blackdog1987.onedollar.entity.TGoodsEntity;
import com.gmail.blackdog1987.onedollar.entity.TGoodsShowEntity;
import com.gmail.blackdog1987.onedollar.entity.TUserAddressEntity;
import com.gmail.blackdog1987.onedollar.entity.base.Page;
import com.gmail.blackdog1987.onedollar.vo.CartVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository("cartDao")
public class CartDao extends EntityHibernateDao<TGoodsCartEntity>{
    @Autowired
    private BaseJdbcDao baseJdbcDao;

    public List<CartVO> queryByUserId(int userid){
        String sql = "SELECT c.*,\n" +
                "       g.goods_name,\n" +
                "       p.old_price,\n" +
                "       p.discount_price,\n" +
                "       pic.pic_url\n" +
                "FROM t_goods_cart c\n" +
                "LEFT JOIN t_goods g ON c.goods_id = g.goods_id\n" +
                "LEFT JOIN t_goods_price p ON c.price_id = p.id\n" +
                "LEFT JOIN t_goods_picture pic ON g.goods_id = pic.goods_id\n" +
                "AND pic.is_main = 1\n" +
                "WHERE user_id = ?";

        return JdbcUtil.queryForList(baseJdbcDao, CartVO.class, sql, new Object[]{userid});
    }
}
